from transliterate import translit
from ..speech_synthesizers import Speak, New_Speak
import configs

# obj_new_speak = New_Speak()
obj_speak = Speak()


def __speak(syntheesizer, say: str, lang: str = configs.language_name) -> None:
    say = say.replace("  ", "")
    say_en = ""
    say_ru = ""
    say_mess = ""
    language_flag = ""
    for say in say.split(","):
        for word_i in say:
            if word_i in configs.dict_value_str_voice["dict_word"]:
                if language_flag == "ru":
                    say_mess += say_ru
                    say_ru = ""
                say_en += word_i
                language_flag = "en"
            else:
                if language_flag == "en":
                    text = translit(say_en, "ru")
                    say_mess += text
                    say_en = ""
                say_ru += word_i
                language_flag = "ru"
        if len(say_en) != 0:
            say_mess += translit(say_en, "ru")
        elif len(say_ru) != 0:
            say_mess += say_ru
        syntheesizer.speak(say_mess, lang)
        say_mess = ""
        say_en = ""
        say_ru = ""
        language_flag = ""


def speak(_say: str, lang: str = configs.language_name) -> None:
    if lang != "defult":
        pass
    else:
        pass
    if configs.settings["type_sintez"] == "new":
        __speak(obj_speak, _say, lang)
        # __speak(obj_new_speak, _say, lang)
    else:
        __speak(obj_speak, _say, lang)
